package com.hyz.util;

import client.AssetClient;
import com.hyz.pojo.assetSecondment.AssetSecondmentResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import pojo.log.assetSecondment.AssetSecondment;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HGD
 * @date 2022/10/6 17:12
 */
@Component
public class Conversion {
    @Autowired
    private AssetClient assetClient;

    public List<AssetSecondmentResponse> getAssetSecondmentResponse(List<AssetSecondment> assetSecondments) {
        List<AssetSecondmentResponse> responses = new ArrayList<>();
        for (AssetSecondment assetSecondment : assetSecondments) {
            AssetSecondmentResponse response = new AssetSecondmentResponse();
            response.setId(assetSecondment.getId());
            response.setApplicantId(assetSecondment.getApplicantId());
            response.setAssetName(assetClient
                    .getAssetById(assetSecondment.getId())
                    .getAssetName());
            response.setSecondmentReason(assetSecondment.getSecondmentReason());
            response.setStatus(assetSecondment.getStatus().getValue());
            response.setResult(assetSecondment.getResult().getValue());
            response.setIsComplete(assetSecondment.getIsComplete().getValue());
            response.setCreateTime(assetSecondment.getCreateTime().toString());
            responses.add(response);
        }
        return responses;
    }
}
